package com.qiyou.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qiyou.dao.IRemindInfoDao;
import com.qiyou.dao.factory.DaoFactory;
import com.qiyou.entity.RemindInfo;

/**
 * 个人提醒信息
 * 
 * @author 杨强
 */
@WebServlet("/RemindList")
public class RemindListServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public RemindListServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String userID = request.getParameter("id");
        if (userID == null || userID.isEmpty()) {
            response.getWriter()
                    .print("<script type='text/javascript'>alert('您的请求有误!');history.go(-1);</script>");
            return;
        }
        String sql = "where userID='" + userID + "' order by riDate desc";
        IRemindInfoDao dao = DaoFactory.getRemindInfoDao();
        List<RemindInfo> remindInfos = null;
        try {
            remindInfos = dao.getRemindInfos(new Object[] { sql });
        } catch (SQLException e) {
            e.printStackTrace();
        }

        request.setAttribute("remindInfos", remindInfos);
        request.getRequestDispatcher("remindlist.jsp").forward(request,
                response);
    }

}
